using namespace std;
#include <vector>
#include "StdAfx.h"
#include "Pipe.h"
#include "OceanViewFactory.h"

CPipe::CPipe(double iWorkFlow)
{
	this->iWorkFlow = iWorkFlow;
	view = (new  OceanViewFactory())->createPipeView();
}


CPipe::~CPipe(void)
{
}

void CPipe::setSourceConnectorIndex(int iSourceConnectorIndex)
{
	this->iSourceConnectorIndex = iSourceConnectorIndex;
}


void CPipe::setTargetConnectorIndex(int iTargetConnectorIndex)
{
	this->iTargetConnectorIndex = iTargetConnectorIndex;
}


void CPipe::setWorkFlow(double iWorkFlow)
{
	this->iWorkFlow = iWorkFlow;
	correctState();
}

void CPipe::setCurrentFlow(double iCurrentFlow)
{
	this->iCurrentFlow = iCurrentFlow;
	correctState();
}

double CPipe::getWorkFlow()
{
	return iWorkFlow;
}


double CPipe::getCurrentFlow()
{
	return iCurrentFlow;
}

int CPipe::getSourceConnectorIndex()
{
	return iSourceConnectorIndex;
}

int CPipe::getTargetConnectorIndex()
{
	return iTargetConnectorIndex;
}


void CPipe::correctState()
{
	double result = (iCurrentFlow-iWorkFlow)/iWorkFlow;
	if(result<=0.2)
		iState=NORMAL_STATE;
	else if(result>0.4)
		iState=CRITICAL_STATE;
	else
		iState=WARNING_STATE;
}


void CPipe::setPoints(vector<CPoint>* points)
{
	this->vPoints=points;
}

vector<CPoint>* CPipe::getPoints()
{
	return vPoints;
}

	
